<?php
class User_Model_DbTable_User_Row extends Zend_Db_Table_Row_Abstract {
	public function _insert() {
		$this->password = User_Model_Auth::saltPassword($this->email, $this->password);
	}

	protected function _update() {
		if (isset($this->password)) {
			if (strlen($this->password)) {
				$this->password = User_Model_Auth::saltPassword($this->email, $this->password);
			} else {
				unset($this->password);
			}
		}

		if (isset($this->image) && $this->image == '') {
			unset($this->image);
		}
	}

	protected function _delete() {
		if (isset($this->image)) {
			$path = User_Model_User::UPLOAD_PATH . DIRECTORY_SEPARATOR . $this->image;
			if (is_file($path)) {
				@unlink($path);
			}
		}
	}
}